package com.offcn.service;

import com.offcn.dao.CourseDao;
import com.offcn.dao.UserDao;
import com.offcn.dao.daoimpl.CourseDaoImpl;
import com.offcn.pojo.Course;
import com.offcn.pojo.CourseDetail;
import com.offcn.util.PageUtil;

import java.util.List;

public class CourseService {
    private CourseDao courseDao = new CourseDaoImpl();

    public PageUtil<Course> allPageCourse(String pageSize, String currentPage, String search) {
        //查询课程总条数
        Integer totalCount = courseDao.queryAllCount(search);
        //创建分页对象
        PageUtil<Course> pageUtil = new PageUtil<>(totalCount, currentPage, Integer.valueOf(pageSize));
        //分页查询课程
        List<Course> list = courseDao.queryCourseByPage(pageUtil, search);
        pageUtil.setList(list);
        return pageUtil;
    }

    public int deleteCourses(String cids) {
        return courseDao.deleteCourses(cids);
    }

    public int addCourse(Course course) {
        return courseDao.addCourse(course);
    }

    public int updateCourse(Course course) {
        return courseDao.updateCourse(course);
    }

    public int addDetail(CourseDetail courseDetail) {
        return courseDao.addDetail(courseDetail);
    }

    public List<Course> queryAllCourse() {
        return courseDao.queryAllCourse();
    }

    public List<Course> queryByCourseByType(Integer type, Integer limit) {
        return courseDao.queryByCourseByType(type,limit);
    }

    public PageUtil<Course> queryAllByPage(String currentPage, String pageSize, String courseName, String courseType) {
        //查询符合条件的总条数
        int totalCount = courseDao.queryCountByType(courseName, courseType);
        PageUtil<Course> pageUtil = new PageUtil<>(totalCount, currentPage, Integer.valueOf(pageSize));
        //查询符合条件的分页数据
        List<Course> list = courseDao.queryByCourseByTypeLimit(pageUtil, courseName, courseType);
        pageUtil.setList(list);
        return pageUtil;
    }

    public Course queryCourseById(Integer cid) {
        return courseDao.queryCourseById(cid);
    }
}
